#pragma once

#include  "iostream"
#include  "vector"
#include  "stack"
#include  "unordered_map"
#include   "queue"

using namespace std;

//自己很快写出来了
bool validateStackSequences(vector<int> &pushed, vector<int> &popped) {

    stack<int> st;

    int i = 0;
    int j = 0;
    while (i < pushed.size() && j < popped.size()) {
        if (pushed[i] == popped[j]) {
            i++;
            j++;
        } else if (!st.empty() && popped[j] == st.top()) {
            st.pop();
            j++;
        } else {
            st.push(pushed[i]);
            i++;
        }

    }

    while (!st.empty() && j < popped.size()) {
        if (st.top() != popped[j]) {
            return false;
        } else {
            st.pop();
            j++;
        }

    }


    return true;
}